<template>
  <div class="real-info">
    <div class="top">
      <div class="row">
        <item-card color="#fff">
          <img src="@/assets/index/real/icon_配电房.png" alt />
          <div>{{ "配电房数量" }}</div>
          <div class="value" style="margin-right: 20px;">{{ info.roomcount || 0 }}</div>
        </item-card>
        <Spliter width="50" />
        <item-card color="#fff">
          <img src="@/assets/index/real/icon_变压器台数.png" alt />
          <div class="row" style="margin-right: 40px">
            <span>
              <div class="value">{{ info.transformercount || 0 }}台</div>
              <div>{{ '变压器总台数' }}</div>
            </span>
            <spliter-line size="30px" margin="40px" />
            <span>
              <div class="value">{{ info.capacity || 0 }}KVA</div>
              <div>{{ '变压器总容量' }}</div>
            </span>
          </div>
        </item-card>
      </div>
      <spliter-line is-row></spliter-line>
      <div class="row">
        <item-card color="#fff">
          <img src="@/assets/index/real/用电累计容量.png" alt />
          <span style="font-size: 16px">今年用电累计容量</span>
          <span style="margin-right: 24px; font-size: 18px;">
            <span style="color: #308AE7">{{ real.countYearKwh || 0 }}</span> kWh
          </span>
        </item-card>
        <Spliter width="50" />
        <div style="flex: 1"></div>
      </div>
    </div>
    <div class="power">
      <div class="tab">
        <span class="btn">电能耗</span>
      </div>
      <div id="echarts-3-1"></div>
    </div>
    <div class="bottom">
      <item-card color="#fff" class="top-item">
        <div class="row">
          <img src="@/assets/index/real/icon_今日电量.png" alt />
          <div style="margin-left: 20px; width: 150px;">
            <div class="value">
              <span style="color: #308AE7">{{ real.dcountTodayKwh || 0 }}</span>
              Kwh
            </div>
            <div>今日电量</div>
          </div>
          <spliter-line size="32px" margin="30px"></spliter-line>
        </div>
        <div class="row right-row">
          <div style="width: 200px;">
            <div>
              <span>上月同期电量:</span>
              <span>{{ real.dcountPremonthKwh || 0 }} kWh</span>
            </div>
            <div>
              <span>昨日同期电量:</span>
              <span>{{ real.dcountYesKwh || 0 }} kWh</span>
            </div>
          </div>
          <div style="width: 200px;">
            <div>
              <span>上月同期相比:</span>
              <span>{{ real.dperPremonthKwh || 0 }}</span>
            </div>
            <div>
              <span>昨日同期相比:</span>
              <span>{{ real.dperYesKwh || 0 }}</span>
            </div>
          </div>
        </div>
      </item-card>
      <item-card color="#fff">
        <div class="row">
          <img src="@/assets/index/real/icon_今日电量.png" alt />
          <div style="margin-left: 20px; width: 150px;">
            <div class="value">
              <span style="color: #308AE7">{{ real.mcountmonthKwh || 0 }}</span>
              Kwh
            </div>
            <div>本月电量</div>
          </div>
          <spliter-line size="32px" margin="30px"></spliter-line>
        </div>
        <div class="row right-row">
          <div style="width: 200px;">
            <div>
              <span>上年同期电量:</span>
              <span>{{ real.mcountPreyearKwh || 0 }} kWh</span>
            </div>
            <div>
              <span>上月同期电量:</span>
              <span>{{ real.mcountYesKwh || 0 }} kWh</span>
            </div>
          </div>
          <div style="width: 200px;">
            <div>
              <span>上年同期相比:</span>
              <span>{{ real.mperPreyearKwh || 0 }}</span>
            </div>
            <div>
              <span>上月同期相比:</span>
              <span>{{ real.mperYesKwh || 0 }}</span>
            </div>
          </div>
        </div>
      </item-card>
    </div>
  </div>
</template>

<script>
import ItemCard from "../ItemCard";
import Spliter from "@/components/Spliter";
import SpliterLine from "@/components/SpliterLine";
import echarts from "echarts";
import { legend } from "@/utils/echarts";
export default {
  components: {
    ItemCard,
    Spliter,
    SpliterLine
  },
  props: {
    real: {
      type: Object,
      default: null
    },
    info: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      echarts: null
    };
  },
  mounted() {
    this.echarts = echarts.init(document.getElementById("echarts-3-1"));
    this.setOption();
  },
  methods: {
    setOption() {
      const xData = this.real.headers;
      const option = {
        color: ["#308AE7", "#FF66B7"],
        grid: {
          top: 35,
          bottom: 10,
          left: 5,
          right: 20,
          containLabel: true
        },
        legend,
        xAxis: {
          type: "category",
          data: xData
        },
        yAxis: {
          type: "value",
          name: "单位：( kWh )",
          axisTick: {
            show: false
          },
          nameTextStyle: {
            align: "left"
          }
        },
        series: [
          {
            data: this.real.data1,
            name: "今日",
            type: "bar",
            barWidth: 10,
            barGap: 0
          },
          {
            data: this.real.data2,
            name: "昨日",
            type: "bar",
            barWidth: 10,
            barGap: 0
          }
        ]
      };
      this.echarts.setOption(option);
    }
  }
};
</script>

<style lang="scss" scoped>
.real-info {
  padding: 10px;
  font-size: 14px;
}
.item-card {
  flex: 1;
  display: flex;
  background: #fff;
  text-align: center;
  line-height: 1.3;
  font-size: 14px;
  justify-content: space-between;
  align-items: center;
  & > img {
    margin-right: 10px;
    width: 40px;
    height: 40px;
  }
  .row {
    margin: 0;
    position: relative;
    .com-spliter-line {
      margin: 0 40px;
    }
  }
  .value {
    font-size: 16px;
  }
  .right-icon {
    padding-right: 10px;
    display: flex;
    align-items: center;
    img {
      width: 28px;
      height: 28px;
      margin-right: 14px;
    }
  }
}
.top {
  .item-card {
    flex: 1;
    display: flex;
    background: #fff;
    text-align: center;
    line-height: 1.3;
    font-size: 14px;
    justify-content: space-between;
    align-items: center;
    .row {
      margin: 0;
      position: relative;
      .com-spliter-line {
        margin: 0 40px;
      }
    }
    .value {
      font-size: 16px;
    }
    .right-icon {
      padding-right: 10px;
      display: flex;
      align-items: center;
      img {
        width: 28px;
        height: 28px;
        margin-right: 14px;
      }
    }
  }
}
.power {
  .tab {
    .btn {
      display: inline-block;
      height: 22px;
      line-height: 22px;
      width: 85px;
      text-align: center;
      border: 1px solid rgba(230, 230, 230, 1);
      border-radius: 12px;
      background: #eeeeee;
      color: #308ae7;
    }
  }
  #echarts-3-1 {
    height: 100px;
  }
}
.bottom {
  margin-top: 10px;
  .value {
    font-size: 18px;
  }
  .item-card {
    padding: 6px;
  }
  .top-item {
    margin-bottom: 10px;
  }
  .right-row {
    flex: 1;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
}
</style>
